package com.pan.creational.proto;

import com.pan.creational.proto.entity.MyReport;
import com.pan.creational.proto.entity.Person;


/**
 * 原型设计模式
 */
public class PrototypeApplication {
    public static void main(String[] args) throws Exception {

        System.out.println("=============浅拷贝==============");
        MyReport report = new MyReport(1, new Person("ppa",23,"male"),"114514151919810");
        //浅拷贝地址不相同，值相同，成员变量的如果是地址引用的，地址是相同的，拷贝出来的对象的成员变量仍然指向原来的地址
        MyReport cloneReport = report.clone();
        System.out.println("report="+report);
        System.out.println("cloneReport="+cloneReport);
        System.out.println("cloneReport==report  "+(cloneReport==report));
        System.out.println("cloneReport.getAuthor() == report.getAuthor  "+(cloneReport.getAuthor()==report.getAuthor()));



        System.out.println("\n\n=============深拷贝==============");
        //深拷贝，使用了序列化来实现，完完全全只是值相同 无论是对象本身还是对象的成员
        cloneReport = report.deepClone();
        System.out.println("report="+report);
        System.out.println("cloneReport="+cloneReport);
        System.out.println("cloneReport==report  "+(cloneReport==report));
        System.out.println("cloneReport.getAuthor() == report.getAuthor  "+(cloneReport.getAuthor()==report.getAuthor()));

    }

}
